#pragma once

#include <string>

#define Die(code) do{ exit(code); }while(0)

#define CONV(v) (struct sockaddr*)(v)

enum{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR
};

// 1.true&&字符串     2.true&&空串     3.false&&空串   
bool ParseOneLine(std::string& req_str, std::string* out, const std::string& sep)
{
    auto pos = req_str.find(sep);
    if (pos == std::string::npos) return false;
    *out = req_str.substr(0, pos);
    req_str.erase(0, pos + sep.size());
    return true;
}

bool SplitString(const std::string& header, std::string* key, std::string* value, const std::string& sep)
{
    auto pos = header.find(sep);
    if (pos == std::string::npos) return false;
    *key = header.substr(0, pos);
    *value = header.substr(pos + sep.size());
    return true;
}